{extend name="Public:base"/}

{block name="main"}
<div class="box-info">
    <form id="myform" name="myform" action="{:U('Category/edit')}" method="post">

        <ul class="nav nav-tabs" role="tablist">
            <li class="nav-item">
                <a class="nav-link active" data-toggle="tab" href="#tab1">基本设置</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" data-toggle="tab" href="#tab2">SEO设置</a>
            </li>
            <li class="nav-item">
                <a class="nav-link" data-toggle="tab" href="#tab3">扩展字段</a>
            </li>
        </ul>
        <div class="tab-content mt-2">
            <div class="tab-pane fade show active" id="tab1">
                <div class="form-group row">
                    <label class="col-md-2 text-right">上级栏目</label>
                    <div class="col-md-5">
                        <select name="parentid" class="form-control" <?php if($data['parentid'] == 0):?>disabled<?php endif;?>>
                            <option value="0">作为一级栏目</option>
                            {$select_categorys}
                        </select>
                    </div>
                </div>
                <div class="form-group row d-none">
                    <label class="col-md-2 text-right">内容模型</label>
                    <div class="col-md-5">
                        {:Form::select(
                        array(
                        'field'=>'modelid',
                        'options'=>$model,
                        'options_key'=>'id,name',
                        'setup'=>array('onchange'=>'changetemplate(this.value)')),
                        $data['modelid']
                        )}
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-md-2 text-right">栏目名称</label>
                    <div class="col-md-5">
                        <input type="text" name="catname" class="form-control" value="{$data['catname']}" />
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-md-2 text-right">英文栏目名称</label>
                    <div class="col-md-5">
                        <input type="text" name="wap_catname" class="form-control" value="{$data['wap_catname']}" />
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-md-2 text-right">继承</label>
                    <div class="col-md-5">
                        <input type="radio" name="inherit" {eq name="data['inherit']" value="1"}checked{/eq} value="1">开启
                        <input type="radio" name="inherit" {eq name="data['inherit']" value="0"}checked{/eq} value="0">关闭
                    </div>
                </div>

                <div class="form-group row">
                    <label class="col-md-2 text-right">栏目图片</label>
                    <div class="col-md-5">
                        <div class="thumb_image">
                            <div id="image_aid_box"></div>
                            <a class="thumbnail" href="javascript:swfupload('image','{:get_auth(1,'1048576',1)}',yesdo);">
                                <img id="image_pic" height="68" src="{if condition="!empty($data['image'])"}{$data['image']}{else/}__IMG__/upload_thumb.png{/if}"></a>
                            <input type="button" value="取消图片" onclick="javascript:clean_thumb('image');" class="btn btn-sm btn-primary"/>
                            <input type="hidden" id="image" name="image" value="{$data['image']}"/>
                        </div>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-md-2 text-right">多栏目设置: </label>
                    <div class="col-md-5">
                        <div class="checkbox-inline">
                            <input type="checkbox" id="chage_all" lay-skin="primary" name="chage_all" value="1"/>将以下设置应用到所有子栏目
                        </div>
                    </div>
                </div>
                <div class="form-group row" >
                    <label class="col-md-2 text-right">pc导航</label>
                    <div class="col-md-5">
                        {:Form::radio(array('field'=>'ismenu','options'=>array('1'=>'是','0'=>'否')), $data['ismenu'])}
                    </div>
                </div>
                <div class="form-group row" >
                    <label class="col-md-2 text-right">wap导航</label>
                    <div class="col-md-5">
                        {:Form::radio(array('field'=>'is_wap_menu','options'=>array('1'=>'是','0'=>'否')), $data['is_wap_menu'])}
                    </div>
                </div>
                <div class="form-group row" >
                    <label class="col-md-2 text-right">新窗口打开</label>
                    <div class="col-md-5">
                        {:Form::radio(array('field'=>'isblank','options'=>array('1'=>'是','0'=>'否')), $data['isblank'])}
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-md-2 text-right">分页条数</label>
                    <div class="col-md-5">
                        <input type="text" name="pagesize" class="form-control w-100px" value="{if condition="!empty($data['pagesize'])"}{$data['pagesize']}{/if}" size="3" /> <p class="text-danger">为空时默认值为系统设置的值</p>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-md-2 text-right">列表页模板</label>
                    <div class="col-md-5">
                        <input name="template_list" class="form-control w-300px" value="{$data.template_list}">
                        &nbsp;&nbsp;
                        <input type="checkbox" lay-skin="primary" class="pull-left" id="listtype" name="listtype"  onclick="javascript:templatetype();" value="1"  {if condition="!empty($data['listtype'])"}checked{/if} />是否为封面栏目
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-md-2 text-right">内容页模板</label>
                    <div class="col-md-5">
                        <input name="template_show" class="form-control w-300px" value="{$data.template_show}">
                    </div>
                </div>
            </div>
            <div class="tab-pane fade" id="tab2" role="tabpanel" aria-labelledby="tab2-tab">
                <div class="form-group row">
                    <label class="col-md-2 text-right">栏目标题</label>
                    <div class="col-md-5">
                        <input name="title" type="text" value="{$data['title']}" class="form-control">
                        <label>针对搜索引擎设置的标题</label>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-md-2 text-right">栏目关键词</label>
                    <div class="col-md-5">
                        <input name="keywords" type="text" value="{$data['keywords']}" class="form-control">
                        <label>关键字中间用半角逗号隔开</label>
                    </div>
                </div>
                <div class="form-group row">
                    <label class="col-md-2 text-right">栏目描述</label>
                    <div class="col-md-5">
                        <textarea name="description" rows="5" cols="60" class="form-control">{$data['description']}</textarea>
                        <label >针对搜索引擎设置的网页描述</label>
                    </div>
                </div>
            </div>
            <div class="tab-pane fade" id="tab3">
                <div class="row">
                    <div class="col-6">
                        <div class="card ">
                            <div class="card-body extend_list">
                                {volist name="extendList" id="vo"}
                                <div class="form-group">
                                    <label>{$vo.setting.title}{eq name="Think.APP_ENV" value="dev"}(<a href="javascript:;;" class="extend_del" data-fid="{$vo.fid}">删除</a>){/eq}</label>
                                    <div class="y-bg">
                                        {switch name="vo.type"}
                                        {case value="input"}
                                        <input type="text" class="form-control" style="{$vo.setting.style}"  name="extend[{$vo.fieldname}]" value="{$data['setting']['extend'][$vo['fieldname']]}" placeholder="{$vo.setting.tips}">
                                        {/case}
                                        {case value="textarea"}
                                        <textarea class="form-control" name="extend[{$vo.fieldname}]" style="{$vo.setting.style}" placeholder="{$vo.setting.tips}">{$data['setting']['extend'][$vo['fieldname']]}</textarea>
                                        {/case}
                                        {case value="password"}
                                        <input type="password" class="input" style="{$vo.setting.style}"  name="extend[{$vo.fieldname}]" value="{$data['setting']['extend'][$vo['fieldname']]}" placeholder="{$vo.setting.tips}">
                                        {/case}
                                        {case value="radio"}
                                        {volist name="vo['setting']['option']" id="rs"}
                                        <label>
                                            <input name="extend[{$vo.fieldname}]" value="{$rs.value}" type="radio"  {if condition=" $data['setting']['extend'][$vo['fieldname']] == $rs['value'] "}checked{/if}> {$rs.title}
                                        </label>
                                        {/volist}
                                        {/case}
                                        {case value="checkbox"}
                                        {volist name="vo['setting']['option']" id="rs"}
                                        <label>
                                            <input name="extend[{$vo.fieldname}][]" value="{$rs.value}" type="checkbox"  {if condition=" in_array($rs['value'],$data['setting']['extend'][$vo['fieldname']]) "}checked{/if}> {$rs.title}
                                        </label>
                                        {/volist}
                                        {/case}
                                        {/switch}
                                        <br/>{literal}<font color="#999999">模板调用：{:{/literal}getCategory({$data.catid},'extend.{$vo.fieldname}')}</font>
                                    </div>
                                </div>
                                {/volist}
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>

        <div class="form-actions">
            <input type="hidden" name="id" value="{$data.id}">
            <button type="submit" class="btn btn-primary">提交</button>
            <button type="button" class="btn btn-danger" onclick="javascript:history.back(-1);return false;">返回</button>
        </div>
    </form>
</div>

{/block}

{block name="script"}


<script type="text/javascript">
    //扩展字段处理
    function extend_type(type){
        if(type == 'radio' || type == 'checkbox'){
            $('.setting_radio').show();
            $('.setting_radio textarea').attr('disabled',false);
        }else{
            $('.setting_radio').hide();
            $('.setting_radio textarea').attr('disabled',true);
        }
    }

    $(function(){
        //删除扩展字段
        $('.extend_list .extend_del').click(function(){
            var fid = $(this).data('fid');
            if(fid){
                $(this).parent('label').parent('div').remove();
                var extenddelete = $('input[name="extenddelete"]').val();
                if(extenddelete == ''){
                    extenddelete = fid;
                }else{
                    extenddelete = extenddelete+'|'+fid;
                }
                $('input[name="extenddelete"]').val(extenddelete);
            }
        });
        //添加扩展字段
        $('.add_extend a').click(function(){
            var fieldname = $('input[name="extend_add[fieldname]"]').val();
            var type = $('select[name="extend_add[type]"]').val();
            var setting = {};
            setting.title = $('input[name="extend_add[setting][title]"]').val();
            setting.tips = $('input[name="extend_add[setting][tips]"]').val();
            setting.style = $('input[name="extend_add[setting][style]"]').val();
            setting.option = $('textarea[name="extend_add[setting][option]"]').val();

            if(fieldname == ''){
                alert("键名不能为空！");
                return false;
            }else{
                if(fieldname.replace(/^[0-9a-zA-Z_]{1,}$/g) != 'undefined'){
                    alert("键名只允许数字，字母，下划线！");
                    return false;
                }
            }
            if(type == ''){
                alert("类型不能为空！");
                return false;
            }
            if(setting.title == ''){
                alert("名称不能为空！");
                return false;
            }

            var tpl = '';
            //单选框
            if(type == 'input'){
                tpl = '<div class="form-group"> <label>'+setting.title+'(<a href="javascript:;;" class="extend_del">删除</a>)</label> <div class="y-bg"> ' +
                    '<input type="text" class="input" style="'+setting.style+'"  name="extend['+fieldname+']" value="" placeholder="'+setting.tips+'"> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][fieldname]" value="'+fieldname+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][type]" value="'+type+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][title]" value="'+setting.title+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][tips]" value="'+setting.tips+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][style]" value="'+setting.style+'"/> ' +
                    '<textarea name="extend_config['+fieldname+'][setting][option]" style="display:none;">'+setting.option+'</textarea> </div> </div>';
                $('.extend_list').append(tpl);
            }else if(type == 'textarea'){
                //多行文本框
                tpl = '<div class="form-group"> ' +
                    '<label>'+setting.title+'(<a href="javascript:;;" class="extend_del">删除</a>)</label> ' +
                    '<div class="y-bg"> ' +
                    '<textarea class="form-control" name="extend['+fieldname+']" style="'+setting.style+'" placeholder="'+setting.tips+'"></textarea> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][fieldname]" value="'+fieldname+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][type]" value="'+type+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][title]" value="'+setting.title+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][tips]" value="'+setting.tips+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][style]" value="'+setting.style+'"/> ' +
                    '<textarea name="extend_config['+fieldname+'][setting][option]" style="display:none;">'+setting.option+'</textarea> ' +
                    '</div> </div>';
                $('.extend_list').append(tpl);
            }else if(type == 'password'){
                //密码框
                tpl = '<div class="form-group"> ' +
                    '<label>'+setting.title+'(<a href="javascript:;;" class="extend_del">删除</a>)</label> ' +
                    '<div class="y-bg"> ' +
                    '<input type="password" class="form-control" style="'+setting.style+'"  name="extend['+fieldname+']" value="" placeholder="'+setting.tips+'"> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][fieldname]" value="'+fieldname+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][type]" value="'+type+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][title]" value="'+setting.title+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][tips]" value="'+setting.tips+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][style]" value="'+setting.style+'"/> ' +
                    '<textarea name="extend_config['+fieldname+'][setting][option]" style="display:none;">'+setting.option+'</textarea> ' +
                    '</div> </div>';
                $('.extend_list').append(tpl);
            }else if(type == 'radio'){
                //单选框
                if(setting.option == ''){
                    alert('选项不能为空！');
                    return false;
                }
                var html = '';
                var op = setting.option.split("\n");
                $.each(op,function(i,rs){
                    var at = rs.split("|");
                    html += '<label><input class="form-check-input" name="extend['+fieldname+']" value="'+at[1]+'" type="radio" > '+at[0]+'</label>';
                });
                tpl = '<div class="form-group"> ' +
                    '<label>'+setting.title+'(<a href="javascript:;;" class="extend_del">删除</a>)</label> ' +
                    '<div class="y-bg">'+html+
                    '<input type="hidden" name="extend_config['+fieldname+'][fieldname]" value="'+fieldname+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][type]" value="'+type+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][title]" value="'+setting.title+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][tips]" value="'+setting.tips+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][style]" value="'+setting.style+'"/> ' +
                    '<textarea name="extend_config['+fieldname+'][setting][option]" style="display:none;">'+setting.option+'</textarea> ' +
                    '</div> </div>';
                $('.extend_list').append(tpl);
            }else if(type == 'checkbox'){
                //复选框
                if(setting.option == ''){
                    alert('选项不能为空！');
                    return false;
                }
                var html = '';
                var op = setting.option.split("\n");
                $.each(op,function(i,rs){
                    var at = rs.split("|");
                    html += '<label><input class="form-check-input" name="extend['+fieldname+'][]" value="'+at[1]+'" type="checkbox" > '+at[0]+'</label>';
                });
                tpl = '<div class="form-group"> ' +
                    '<label>'+setting.title+'(<a href="javascript:;;" class="extend_del">删除</a>)</label> ' +
                    '<div class="y-bg">'+html+
                    '<input type="hidden" name="extend_config['+fieldname+'][fieldname]" value="'+fieldname+'"/>' +
                    ' <input type="hidden" name="extend_config['+fieldname+'][type]" value="'+type+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][title]" value="'+setting.title+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][tips]" value="'+setting.tips+'"/> ' +
                    '<input type="hidden" name="extend_config['+fieldname+'][setting][style]" value="'+setting.style+'"/> ' +
                    '<textarea class="form-control" name="extend_config['+fieldname+'][setting][option]" style="display:none;">'+setting.option+'</textarea> </div> </div>';
                $('.extend_list').append(tpl);
            }
            //清空
            $('input[name="extend_add[fieldname]"]').val('');
            $('select[name="extend_add[type]"]').val('');
            $('input[name="extend_add[setting][title]"]').val('');
            $('input[name="extend_add[setting][tips]"]').val('');
            $('input[name="extend_add[setting][style]"]').val('');
            //删除扩展字段
            $('.extend_list .extend_del').click(function(){
                $(this).parent('th').parent('tr').remove()
            });
        });
    });
</script>
<script type="text/javascript">
$(document).ready(function() {
    $('#myform').ajaxForm({
        success:  complete,  // post-submit callback
        dataType: 'json'
    });
});

function complete(data){
    if(data.status==1){
        layer.msg(data.info, {
            icon: 1,
            time: 2000 //2秒关闭（如果不配置，默认是3秒）
        }, function(){
            window.location.href = "{$Think.cookie.__forward__}";
            return true;
        });
    }else{
        layer.msg(data.info, {
            icon: 2,
            time: 2000 //2秒关闭（如果不配置，默认是3秒）
        });
    }

}

function urlrule(m){
    if(m==1){
        $('#urlrule').show();
    }else{
        $('#urlrule').hide();
    }
}

urlrule({$data['ishtml']});

</script>
{/block}